{extend name="adminblue/base" /} {block name="resources"/}
<style>.table-class tbody td{border:0;vertical-align: middle;}</style>
{/block}
{block name="main"}
<div class="options-btn">
	<button class="btn-common" onclick="location.href='{:__URL('ADMIN_MAIN/config/addshopad')}';">添加广告</button>
</div>
<table class="table-class">
	<colgroup>
		<col style="width: 5%;">
		<col style="width: 30%;">
		<col style="width: 20%;">
		<col style="width: 10%;">
		<col style="width: 11%;">
	</colgroup>
	<thead>
		<tr align="center">
			<th><input type="checkbox"  onclick="CheckAll(this)"></th>
			<th>轮播图片</th>
			<th>链接地址</th>
			<th>类型</th>
			<th>操作</th>
		</tr>
	</thead>
	<colgroup>
		<col style="width: 5%;">
		<col style="width: 30%;">
		<col style="width: 20%;">
		<col style="width: 10%;">
		<col style="width: 11%;">
	</colgroup>
	<tbody></tbody>
</table>
{/block}
{block name="script"}
<script type="text/javascript">
$(function(){
	LoadingInfo(1);
})
function LoadingInfo(page_index) {
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/shopadlist')}",
		data : {
			"page_index" : page_index,
			"page_size" : $("#showNumber").val()
		},
		success : function(data) {
			if (data['data'].length > 0) {
				$(".table-class tbody").empty();
				for (var i = 0; i < data['data'].length; i++) {
					var html = '';
					html += '<tr align="center">';
					html += '<td><input name="sub" type="checkbox" value="'+ data['data'][i]['id']+'" ></td>';
					html += '<td><img src="'+ __IMG(data['data'][i]['ad_image'])+'" style="height:50px;"/></td>';
					html += '<td>' + data['data'][i]["link_url"] + '</td>';
					if(data['data'][i]["type"] == 0){
						html += '<td>PC端</td>';
					}else{
						html += '<td>手机端</td>';
					}
					html += '<td><a href="'+__URL('ADMIN_MAIN/config/updateshopad?id=' + data['data'][i]["id"])+'">编辑</a> ';
					html += '<a href="javascript:;" onclick="delShopAd('+ data['data'][i]["id"] +')">删除</a></td> ';
					html += '</tr>';
					$(".table-class tbody").append(html);
				}
			} else {
				var html = '<tr align="center"><td colspan="5">暂无符合条件的数据记录</td></tr>';
				$(".table-class tbody").html(html);
			}
		}
	});
}

//全选
function CheckAll(event){
	var checked = event.checked;
	$(".table-class tbody input[type = 'checkbox']").prop("checked",checked);
}

function delShopAd(id){
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/delshopad')}",
		data : { 'id' : id },
		success : function(data) {
			if (data["code"] > 0) {
				showMessage('success', "店铺广告删除成功","{:__URL('ADMIN_MAIN/config/shopadlist')}");
			}else{
				showMessage('error', "店铺广告删除失败");
			}
		}
	});
}
</script>
{/block}